<!doctype html>
<html>
<head>
<title>enumerateDevices: test that enumerateDevices() returns the same result on
  a same-origin iframe.
</title>
</head>
<body>
<h1 class="instructions">Description</h1>
<p class="instructions">This test checks that the result of the
  <code>navigator.mediaDevices.enumerateDevices()</code> method on a same-origin
  iframe matches the results on the main frame.</p>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
var t = async_test(
  "Result of enumerateDevices() on an iframe matches that of the main frame",
   {timeout: 4000});
var iframe = document.createElement('iframe');
window.onmessage = t.step_func(event => {
  if (event.source != iframe.contentWindow)
    return;

  var iframe_devices = JSON.parse(event.data);
  navigator.mediaDevices.enumerateDevices().then(main_devices => {
    assert_equals(main_devices.length, iframe_devices.length);
    for (var i = 0; i < main_devices.length; i++) {
      assert_not_equals(main_devices[i].groupId, iframe_devices[i].groupId);
      assert_equals(main_devices[i].kind, iframe_devices[i].kind);
      assert_equals(main_devices[i].label, iframe_devices[i].label);
    }
    t.done();
  });
});

iframe.src = "resources/MediaDevices-enumerateDevices-iframe-child.html";
document.body.appendChild(iframe);
</script>
</body>
</html>
